package com.task.core.domain.info;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson2.JSON;
import com.task.common.info.PluginInfo;

import lombok.Data;

/**
 * @author 迪迦.
 * @date 2025/1/16 11:26
 */
@Data
public class ClientPluginInfo {
  private Integer id;
  private String code;
  private String pluginName;
  private String pluginPlatformName;
  private Map<String, Object> config;

  public static List<ClientPluginInfo> getList(List<PluginInfo> plugins) {
    if (CollectionUtils.isEmpty(plugins)) {
      return null;
    }
    List<ClientPluginInfo> list = new ArrayList<>();
    plugins.forEach(f -> {
      list.add(new ClientPluginInfo(f));
    });

    return list;
  }

  public ClientPluginInfo(PluginInfo plugin) {
    this.id = plugin.getId();
    this.code = plugin.getCode();
    this.pluginName = plugin.getPluginName();
    this.pluginPlatformName = plugin.getPluginPlatformName();
    if (!StringUtils.isEmpty(plugin.getConfig())) {
      this.config = JSON.parseObject(plugin.getConfig());
    }
  }
}
